package cn.lanqiao.controller;

import cn.lanqiao.entity.ApiResult;
import cn.lanqiao.service.MailService;
import cn.lanqiao.util.ApiResultHandler;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@CrossOrigin(origins="*",maxAge=3600)
public class MailController {

    @Resource
    private MailService mailService;

    @PostMapping("/sendMailCode")
    public ApiResult sendMailCode(@RequestBody Map<String, String> param, HttpServletRequest request){
        String mail = param.get("mail");
        System.out.println(request.getSession().getId());
        return ApiResultHandler.buildApiResult(200, mailService.sendMailCode(mail, request), null);
    }
}
